<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {pp_ads} function plugin
 *
 * File:       function.pp_ads.php<br>
 * Type:       function<br>
 * Name:       pp_ads<br>
 * Date:       24.Feb.2003<br>
 * Purpose:    Prints out a list of radio input types<br>
 * Input:<br>
 *           - title       (optional) - string default "radio"
 *           - value     (required) - array
 *           - options    (optional) - associative array
 *           - checked    (optional) - array default not set
 *           - separator  (optional) - ie <br> or &nbsp;
 *           - output     (optional) - the output next to each radio button
 *           - assign     (optional) - assign the output as an array to this variable
 * Examples:
 * <pre>
 * {pp_ads value=$ids output=$titles}
 * {pp_ads value=$ids title='box' separator='<br>' output=$titles}
 * {pp_ads value=$ids checked=$checked separator='<br>' output=$titles}
 * </pre>
 * @link http://smarty.php.net/manual/en/language.function.html.radios.php {pp_ads}
 *      (Smarty online manual)
 * @author     Christopher Kvarme <christopher.kvarme@flashjab.com>
 * @author credits to Monte Ohrt <monte at ohrt dot com>
 * @version    1.0
 * @param array
 * @param Smarty
 * @return string
 * @uses smarty_function_escape_special_chars()
 */
function smarty_function_pp_ads($params, &$smarty)
{
	require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
	
	$title = null;
	$value = null;
	
	foreach($params as $_key => $_val) {
		switch($_key) {
			case 'title':
                $$_key = (string)$_val;
                break;

			case 'value':
			case 'output':
                $$_key = (string)$_val;
                break;

			case 'assign':
                break;

			default:
                if(!is_array($_val)) {
                    $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
                } else {
                    $smarty->trigger_error("pp_ads: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
                }
                break;
		}
	}

	//
	$_html_result = smarty_function_pp_ads_output($title, $value);
	
	return $_html_result;
}

function smarty_function_pp_ads_output($title, $value) {
	global $LANGUAGE;
	
	if( substr($value, 0, strlen(':')) == ':' ) {
		$ks = explode(':', $value);
		if( sizeof($ks) == 2 ) {
			$value = isset($LANGUAGE[$ks['1']]) ? $LANGUAGE[$ks['1']] : $ks['1'];
		} else {
			$value = isset($LANGUAGE[$ks['1']][$ks['2']]) ? $LANGUAGE[$ks['1']][$ks['2']] : $ks['2'];
		}
	}

	//
	$id = substr(md5($title), 0, 6);
	$_output = '';
	
	$_output .= '<div class="infoBox">';
	$_output .= '<div class="infoBoxHeading">';
	$_output .= '<span class="h">' . smarty_function_escape_special_chars($title) . '</span>';
	$_output .= '</div>';
	$_output .= '<div class="infoBoxContent" id="' . $id . '">';
	
	$_output .= '<div class="infoBoxItem">';
	$_output .= $value;
	$_output .= '</div>';
	
	$_output .= '</div>';
	$_output .= '</div>';

    return $_output;
}
//
?>
